import React, { useEffect } from 'react';
import { history, useLocation } from 'umi';
import { useUserStore } from '@/stores/userStore';

const AuthWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => {
    const { token } = useUserStore();
    const location = useLocation();

    useEffect(() => {
        // 如果没有token且不在登录页，则跳转到登录页
        if (!token && location.pathname !== '/login') {
            history.replace('/login');
        }
    }, [token, location.pathname]);

    return <>{children}</>;
};

export default AuthWrapper; 